﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MINERP.GroupMember.IView;
using MINERP.BLL.Statistics;

namespace MINERP.GroupMember.Presenter
{
    public class LookHistory_BKPresenter
    {
        private ILookHistory_BK _view;
        private PerformanceBLL _bll;

        public LookHistory_BKPresenter(ILookHistory_BK view)
        {
            _view = view;
            _bll = new PerformanceBLL();
            GetResult();
        }

        public void GetResult()//初始化界面数据
        {
            List<PerformanceView> listResult = new List<PerformanceView>();
            DateTime startDate = _view.StartDate;
            DateTime endDate = _view.EndDate;
            if (startDate == DateTime.MinValue||startDate==null)
            {
                startDate = DateTime.Now.Date;
            }
            if (endDate == null||endDate==DateTime.MinValue)
            {
                endDate = startDate;

            }
            if (!string.IsNullOrEmpty(DataTransfer.UserName) && !string.IsNullOrEmpty(DataTransfer.GroupName))
            {
                listResult = _bll.GetPerformanceAll(DataTransfer.GroupName, DataTransfer.UserName, startDate, endDate);
            }
            double totalAreaCount = listResult.Sum(l => l.Areas);
            _view.ShowResult(listResult);
            _view.ShowCount(totalAreaCount);

        }

    }
}
